package com.lqq.school.controller;


import com.lqq.school.domain.LeaveRecord;
import com.lqq.school.mapper.LeaveRecordMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lqq
 * @since 2021-06-13
 */
@Controller
public class LeaveRecordController {
    @Resource
    private LeaveRecordMapper leaveRecordMapper;

    @RequestMapping("/toLeave")
    public String toLeave() {
        return "/stu/leave";
    }

    @PostMapping("/leave")
    public String leave(LeaveRecord leaveRecord) {
        System.out.println(leaveRecord.getLeaveDate());

        int insert = leaveRecordMapper.insert(leaveRecord);

        if (insert > 0) {
            System.out.println("请假成功！");
        }
        return "/stu/dashboard";
    }

    @GetMapping("/leaveList")
    public String leaveList(Model model) {
        List<LeaveRecord> list = leaveRecordMapper.selectList(null);
        model.addAttribute("list", list);
        return "/admin/leavelist";
    }

    @GetMapping("/leave/delete/{stuId}")
    public String delete(@PathVariable("stuId") Long stuId) {
        System.out.println("走了啧啧啧");
        int delete = leaveRecordMapper.deleteById(stuId);
        if (delete > 0) {
            System.out.println("删除1条数据成功！");
        }
        return "redirect:/leaveList";
    }

}


